package spring.my.suveng.aspect.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * author: Veng Su
 * email: suveng@163.com
 * date: 2018/8/14 16:22
 */

@Component(value = "annotationAspect")
@Aspect
public class AnnotationAspect {

    //before 切
    @Before(value = "execution(* *..*.*.say())")
    public void beforeF(){
        System.out.println("我是before");
    }
    //after 切
    @After(value = "execution(* *..*.*.say())")
    public void afterF(){
        System.out.println("我是after");
    }
    //after_throwing 切
    @AfterThrowing(value = "execution(* *..*.*.say())")
    public void afterTF(){
        System.out.println("我是after-throwing");
    }
    //after-returning 切
    @AfterReturning(value = "execution(* *..*.*.say())")
    public void afterRF(){
        System.out.println("我是after-returning");
    }
    //around 切 要把joinpoint给传进来
    @Around(value = "AnnotationAspect.say()")
    public void aroundF(ProceedingJoinPoint joinPoint){
        System.out.println("前around");
        try {
            joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("后 around");
    }
    // 如果切入表达式，大部分都是一样的话，则可考虑抽取出来，简单利用
    @Pointcut(value = "execution(* *..*.*.say())")
    public void say() {}
}
